<?php

if_get('/address_unit_values', function ()
{
    list(
        $inputs['value'], $inputs['status'], $inputs['address_unit_turn_id']
    ) = input_list(
        'value', 'status', 'address_unit_turn_id'
    );
    $inputs = array_filter($inputs, 'not_null');

    return render('address_unit_value/list', [
        'address_unit_values' => dao('address_unit_value')->find_all_by_column($inputs),
    ]);
});

if_get('/address_unit_values/add', function ()
{
    return render('address_unit_value/add');
});

if_post('/address_unit_values/add', function ()
{
    $address_unit_value = address_unit_value::create();

    $address_unit_value->value = input('value');
    $address_unit_value->status = input('status');
    $address_unit_value->address_unit_turn_id = input('address_unit_turn_id');

    return redirect('/address_unit_values');
});

//todo::detail

if_get('/address_unit_values/update/*', function ($address_unit_value_id)
{
    $address_unit_value = dao('address_unit_value')->find($address_unit_value_id);
    otherwise($address_unit_value->is_not_null(), 'address_unit_value not found');

    return render('address_unit_value/update', [
        'address_unit_value' => $address_unit_value,
    ]);
});

if_post('/address_unit_values/update/*', function ($address_unit_value_id)
{
    $address_unit_value = dao('address_unit_value')->find($address_unit_value_id);
    otherwise($address_unit_value->is_not_null(), 'address_unit_value not found');

    $address_unit_value->value = input('value');
    $address_unit_value->status = input('status');
    $address_unit_value->address_unit_turn_id = input('address_unit_turn_id');

    return redirect('/address_unit_values');
});

if_post('/address_unit_values/delete/*', function ($address_unit_value_id)
{
    $address_unit_value = dao('address_unit_value')->find($address_unit_value_id);
    otherwise($address_unit_value->is_not_null(), 'address_unit_value not found');

    $address_unit_value->delete();

    return redirect('/address_unit_values');
});
